{% from "filtered-jobs.html" import filtered_jobs with context %}
{% extends "layout.html" %}
{% block title %}PR {{ number }}{% endblock %}
{% block head %}
    <script src="{{ base_path }}/common_static/focus_on_keyup.js"></script>
{% endblock %}
{% block content %}
    <h1>{{ pr.title }} <a rel="noopener" href="https://github.com/{{ repo }}/pull/{{ pr.number }}"><span class="gh-number">#{{ pr.number }}</span></a></h1>

    {% if batch is defined %}
    <div class="attributes">
      <div>batch: <a rel="noopener" href="{{ base_path }}/batches/{{ batch['id'] }}">{{ batch['id'] }}</a></div>
      <div>artifacts:
        <a rel="noopener"  target="_blank" href="{{ artifacts_url }}">{{ artifacts_uri }}</a>
        <i class="material-icons text-icon">open_in_new</i>
      </div>
      <div>cost: {{ batch['cost'] }}</div>
      {% for name, value in batch['attributes'].items() %}
      <div>{{ name }}: {{ value }}</div>
      {% endfor %}
      <div>labels: {{ pr.labels|join(", ") }}</div>
    </div>
    <form action="{{ base_path }}/watched_branches/{{ wb.index }}/pr/{{ pr.number }}/retry" method="post">
      <input type="hidden" name="_csrf" value="{{ csrf_token }}"/>
      <button type="submit">Retry</button>
    </form>

    {% if logging_queries is not none %}
    <h2>Logging Queries</h2>
    <div class="logging-queries">
    {% for name, link in logging_queries.items() %}
    <div><a href="{{ link }}">{{ name }}</a></div>
    {% endfor %}
    </div>
    {% endif %}

    <h2>Jobs</h2>
    {{ filtered_jobs(running, failed, pending, completed) }}
    {% elif exception is defined %}
    <p>Build error:</p>
    <pre>
      {{ exception }}
    </pre>
    {% else %}
    No build running.
    {% endif %}

    <h2>Build History</h2>
    {% if history %}
    <table class="data-table">
      <thead>
        <tr>
          <th>id</th>
          <th>state</th>
        </tr>
      </thead>
      <tbody>
        {% for batch in history %}
        <tr>
          <td class="numeric-cell">
            <a rel="noopener" href="{{ base_path }}/batches/{{ batch['id'] }}">{{ batch['id'] }}</a>
          </td>
          <td>
            {% if 'state' in batch and batch['state'] %}
            {{ batch['state'] }}
            {% endif %}
          </td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
    {% else %}
    No builds.
    {% endif %}
{% endblock %}
